//
//  JMPlayerController.m
//  PlayerController
//
//  Created by 赵俊明 on 2018/12/3.
//  Copyright © 2018 赵俊明. All rights reserved.
//

#import "JMPlayerController.h"
#import "JMPlayerControlView.h"
#import "JMSourceModel.h"
#import "Masonry.h"
#import "JMPlayerView.h"

@interface JMPlayerController ()<JMPlayerControlViewDelegate,ZFPlayerDelegate>
@property(nonatomic, weak) UIView *fatherView;
@end

@implementation JMPlayerController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor grayColor];
    
    UIView *fatherView = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:fatherView];
    
    [fatherView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
        make.width.equalTo(self.view);
        make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom);
    }];
    
    JMPlayerView *playerView = [JMPlayerView sharedPlayerView];
    playerView.delegate = self;
    playerView.cellPlayerOnCenter = NO;
    
    // 取出字典中的第一视频URL
    JMSourceModel *playerModel = [JMSourceModel new];
    playerModel.title = @"测试播放";
    playerModel.videoURL = [NSURL URLWithString:@""];
    playerModel.fatherView = fatherView;
//    playerModel.indexPath = weakIndexPath;
    
    // 赋值分辨率字典
    playerModel.resolutionDic = @{};
    
    // player的父视图tag
    playerModel.fatherViewTag = 10;
    
    // 设置播放控制层和model
    [playerView playerModel:playerModel];
    //        [weakSelf.playerView playerControlView:self.controlView playerModel:playerModel];
    // 下载功能
    playerView.hasDownload = YES;
    // 自动播放
    [playerView autoPlayTheVideo];
    
//    JMPlayerControlView *cv = [[JMPlayerControlView alloc] initWithFrame:self.view.bounds];
//    cv.delegate = self;
//    [cv playerModel:model];
    
}

/** 返回按钮事件 */
- (void)jm_controlView:(UIView *)controlView backAction:(UIButton *)sender
{
    [self.navigationController popoverPresentationController];
}
/** cell播放中小屏状态 关闭按钮事件 */
- (void)jm_controlView:(UIView *)controlView closeAction:(UIButton *)sender
{
    
}
/** 播放按钮事件 */
- (void)jm_controlView:(UIView *)controlView playAction:(UIButton *)sender
{
    
}
/** 全屏按钮事件 */
- (void)jm_controlView:(UIView *)controlView fullScreenAction:(UIButton *)sender
{
    
}
/** 锁定屏幕方向按钮时间 */
- (void)jm_controlView:(UIView *)controlView lockScreenAction:(UIButton *)sender
{
    
}
/** 重播按钮事件 */
- (void)jm_controlView:(UIView *)controlView repeatPlayAction:(UIButton *)sender
{
    
}
/** 中间播放按钮事件 */
- (void)jm_controlView:(UIView *)controlView cneterPlayAction:(UIButton *)sender
{
    
}
/** 加载失败按钮事件 */
- (void)jm_controlView:(UIView *)controlView failAction:(UIButton *)sender
{
    
}
/** 下载按钮事件 */
- (void)jm_controlView:(UIView *)controlView downloadVideoAction:(UIButton *)sender
{
    
}
/** 切换分辨率按钮事件 */
- (void)jm_controlView:(UIView *)controlView resolutionAction:(UIButton *)sender
{
    
}
/** slider的点击事件（点击slider控制进度） */
- (void)jm_controlView:(UIView *)controlView progressSliderTap:(CGFloat)value
{
    
}
/** 开始触摸slider */
- (void)jm_controlView:(UIView *)controlView progressSliderTouchBegan:(UISlider *)slider
{
    
}
/** slider触摸中 */
- (void)jm_controlView:(UIView *)controlView progressSliderValueChanged:(UISlider *)slider
{
    
}
/** slider触摸结束 */
- (void)jm_controlView:(UIView *)controlView progressSliderTouchEnded:(UISlider *)slider
{
    
}
/** 控制层即将显示 */
- (void)jm_controlViewWillShow:(UIView *)controlView isFullscreen:(BOOL)fullscreen
{
    
}
/** 控制层即将隐藏 */
- (void)jm_controlViewWillHidden:(UIView *)controlView isFullscreen:(BOOL)fullscreen
{
    
}

/** 返回按钮事件 */
- (void)jm_playerBackAction:(NSInteger)currentTime
{
    [self.navigationController popoverPresentationController];
}
/** 下载视频 */
- (void)jm_playerDownload:(NSString *)url
{
    NSLog(@"下载视频");
}
/** 控制层即将显示 */
- (void)jm_playerControlViewWillShow:(UIView *)controlView isFullscreen:(BOOL)fullscreen
{
    NSLog(@"控制层即将显示");
}
/** 控制层即将隐藏 */
- (void)jm_playerControlViewWillHidden:(UIView *)controlView isFullscreen:(BOOL)fullscreen
{
    NSLog(@"控制层即将隐藏 ");
}
/** 播放失败回调 */
- (void)jm_playerFaild:(JMSourceModel *)playerModel
{
    NSLog(@"播放失败回调");
}

@end
